package com.xintoucloud.pbs.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.pbs.dao.MenuDao_3;
import com.xintoucloud.pbs.entity.Menu_3;
import com.xintoucloud.pbs.model.Attributes;
import com.xintoucloud.pbs.model.Node;
import com.xintoucloud.pbs.service.MenuService_3;
@Service@Transactional
public class MenuServiceImpl_3 implements MenuService_3 {
	@Autowired
	private MenuDao_3 menuDao_3;
	@Override
	public List<Node> listNodeByParentId(Integer parentId) {
				List<Menu_3> menus3=null;
				if(parentId==0) {
					//查找所有父节点为0的
					menus3=menuDao_3.listMenuOnNullParentId();
				}else {
					menus3=menuDao_3.listMenusByParentId(parentId);
				}
				List<Node> nodes=new ArrayList<>();
				for (Menu_3 menu : menus3) {
					Node node=new Node();
					node.setIconCls(menu.getIconCls());
					node.setId(menu.getId());
					node.setText(menu.getMenuName());
					Attributes attributes=new Attributes();
					attributes.setUrl(menu.getUrl());
					node.setAttributes(attributes);
					List<Node> childs=listNodeByParentId(menu.getId());
					node.setChildren(childs);
					if(childs!=null) {
					nodes.add(node);
					node.setState("closed");
					}else {
					node.setState("open");
					}
				}
				return nodes;
		}
}
